package com.yjck.fm.login.dao.impl;


import java.sql.ResultSet;
import java.sql.SQLException;

import com.yjck.fm.login.bean.User;
import com.yjck.fm.login.dao.LoginDAO;
import com.yjck.fm.util.DBUtil;

public class LoginDAOImpl implements LoginDAO{
	private DBUtil dbUtil;
	public void setDbUtil(DBUtil dbUtil) {
		this.dbUtil = dbUtil;
	}
	public boolean validate(String email, String passwd) {
		int flag =0;
		String sql = "select count(*) from user where email = ? and passwd = ?";
		Object[] params = new Object[]{email,passwd};
		flag = dbUtil.getCount(sql, params);
		if(flag == 1){
			return true;
		}else{
			return false;
		}
		
	}
	public User getUser(String email) {
		Object[] params = new Object[]{email};
		String sql = "SELECT id,email,if(sex=1,'男','女') sex,uname from user where email = ?";
		ResultSet rs = dbUtil.getRs(sql, params);
		User user = new User();
		try {
			while(rs.next()){
				user.setId(rs.getInt("id"));
				user.setSex(rs.getString("sex"));
				user.setName(rs.getString("uname"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user;
	}
	

}
